{template 'common/header'}
<style>
	.main{
		margin: 0 0 30px 0;
	}
</style>
<ul class="nav nav-tabs">
	<li {if $op == 'index'}class="active"{/if}><a href="{php echo $this->createWebUrl('news', array('op' => 'index'))}">文章列表</a></li>
	<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('news', array('op' => 'post'))}">发布文章</a></li>
	
</ul>
{if $op == 'index'}
<div class="main">
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
            <form action="" method="post" class="form-horizontal form" onsubmit="return formcheck(this)">
                <table class="table table-hover" style="margin-top: 15px;">
                    <thead class="navbar-inner">
                    <tr>
                    	<th class="text-center" style="width:10%;">编号</th>
                    	<th class="text-center" style="width:20%;">标题</th>
                        <th class="text-center" style="width:10%;">图片</th>
                    	<th class="text-center" style="width:20%;">点击数</th>
                        <th class="text-center" style="width:10%;">排序</th>
                    	<th class="text-center" style="width:10%;">需要权限</th>
                        <th class="text-right" style="width:20%;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $row}
                    <tr>
                    	<td class="text-center">{$row['id']}</td>
						<td class="text-center">{$row['title']}</td>
                        <td class="text-center">
                            <img src="{$_W['attachurl']}{$row['thumb']}" style="width:45px;height:30px" />
                        </td>
						<td class="text-center">{$row['click']}</td>
                        <td class="text-center">{$row['sort']}</td>
						<td class="text-center">{$row['weight']}</td>
                        <td style="text-align:right;">
                            <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('news', array('op' => 'post', 'id' => $row['id']))}" title="编辑"><i class="fa fa-pencil"></i></a>
                            <a class="btn btn-default btn-sm" onclick="return confirm('是否要删除？');return false;" href="{php echo $this->createWebUrl('news', array('op' => 'delete', 'id' => $row['id']))}" title="删除"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    <tr>
                        <td colspan="6">
                            <input type="hidden" name="token" value="{$_W['token']}"/>
                        </td>
                    </tr>
                    </tbody>
                </table>
                
				<div class="pull-right">
					{$pager}
				</div>
                
            </form>
        </div>
    </div>
  
</div>
</div>
{elseif $op == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" >
    <div class="panel panel-default">
        <div class="panel-heading">文章发布 </div>
        <div class="panel-body">   
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章标题</label>
                <div class="col-sm-9">
                    <input type="text" name="title" class="form-control" value="{$item['title']}" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                <div class="col-sm-9">
                    <input type="number" name="sort" class="form-control" value="{$item['sort']}" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属分类</label>
                <div class="col-sm-9">
                    <select name="newclass_id" class="form-control">
                        {loop $lists $row}
                        <option value="{$row['id']}" {if $row['id']==$item['newclass_id']}selected{/if}>{$row['name']}</option>
                        {/loop}
                    </select>
                   
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">缩略图片</label>
                <div class="col-sm-9">
            		{php echo tpl_form_field_image('thumb',$item['thumb'], '/web/resource/images/nopic.jpg', array('width' => 640, 'height' => 320))}
                </div>
            </div>
            
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">简要描述</label>
				<div class="col-xs-9">
					<textarea class="form-control" name="desc" rows="5" style="100%" />{$item['desc']}</textarea>
				</div>			
			</div>
            
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">阅读权限</label>
                <div class="col-sm-9">
                    <input type="number" name="weight" class="form-control" value="{$item['weight']}" />
                    <p class="help-block">用户组权限值必须大于这个权限值可以阅读</p>
                </div>      
            </div>


			<div class="form-group">
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章内容</label>
                    <div class="col-xs-9">
                        <textarea class="form-control richtext" name="content" rows="5">{$item['content']}</textarea>
                    </div>
                </div>
			</div>

        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <input name="submit" type="submit" value="提交" class="btn btn-primary ">
            <input type="hidden" name="token" value="{$_W['token']}"/>
			<input type="hidden" name="id" value="{$item['id']}"/>
        </div>
    </div>
	</form>
</div>
<script>
    require(['util'],function(util){
        util.editor( $(".richtext")[0]);
    });
    require(['jquery', 'util'], function($, util){
    $(function(){
        $('form').submit(function(){
           var title=$("[name='title']").val();
            if(title==''||title==null){
                util.message('请填写文章标题');
                return false;
            }
            var weight=$("[name='weight']").val();
            if(weight==''||weight==null){
                util.message('请填写阅读权限');
                return false;
            }
           var content=$("[name='content']").val();
            if(content==''||content==null){
                util.message('请填写文章内容');
                return false;
            }
            
        });

    });

});
</script>

{/if}

{template 'common/footer'}